<template>
  <div>
    <div style="margin-top: 15px; width: 300px">
      <el-input
        placeholder="请输入姓名"
        v-model="name"
        class="input-with-select"
      >
        <el-button
          slot="append"
          icon="el-icon-search"
          @click="showpage"
        ></el-button>
      </el-input>
    </div>
    <template>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="UsersName" label="姓名" width="180">
        </el-table-column>
        <el-table-column prop="Admin" label="账户" width="180">
        </el-table-column>
        <el-table-column prop="UserImg" label="头像"> </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </template>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageindex"
      :page-sizes="[1, 2, 3, 4]"
      :page-size="pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalcount"
    >
    </el-pagination>
  </div>
</template>

<script >
export default {
  data() {
    return {
      name: "",
      totalcount: 0,
      totalpage: "",
      pageindex: 1,
      pagesize: 2,
      tableData: [],
    };
  },
  methods: {
    showpage() {
      this.$axios
        .get(
          "https://localhost:44353/api/LoginAPI/GetUsers?name=" +
            this.name +
            "&pageindex=" +
            this.pageindex +
            "&pagesize=" +
            this.pagesize +
            ""
        )
        .then((res) => {
          this.tableData = res.data.list;
          this.totalcount = res.data.totalcount;
        });
    },
    handleSizeChange(val) {
      this.pagesize = val;
      this.showpage();
    },
    handleCurrentChange(val) {
      this.pageindex = val;
      this.showpage();
    },
    //修改
    handleEdit(index, row) {
      this.$router.push('/Edit/'+row.UsersId)
      console.log(index, row);
    },
    //删除
    handleDelete(index, row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios
            .delete(
              "https://localhost:44353/api/LoginAPI/Del?UsersId=" + row.UsersId
            )
            .then((res) => {
              if (res.data > 0) {
                this.showpage();
              }
            });
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });

      console.log(index, row);
    },
  },
  created() {
    this.showpage();
  },
};
</script>

<style scoped>
.el-table {
  margin-top: 10px;
}
.el-input-group__prepend {
  background-color: #fff;
}
</style>